﻿/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A
 * copy of the license can be found at http://go.microsoft.com/fwlink/?LinkID=131993. If
 * you cannot locate the Microsoft Public License, please send an email to
 * mixon@microsoft.com. By using this source code in any fashion, you are agreeing to
 * be bound by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Xml.Linq;

namespace MIXOnline.Descry
{
    public partial class Page : UserControl
    {
        private tee myTee = new tee();
        private Random Rand = new Random();
        private bool AscendingRadioIsChecked = true;
        private bool DescendingRadioIsChecked;
        private bool AlphabeticalRadioIsChecked = true;
        private bool ObesityRadioIsChecked;
        private bool Category1Selected;
        private bool Category2Selected;
        private bool Category3Selected;
        private bool Category4Selected;
        private bool Category5Selected;
        private bool Category6Selected;
        private bool Category7Selected;

        private List<Point> TeeLocations = new List<Point>();
        private List<tee> AllTees = new List<tee>();

        private SolidColorBrush LegendHover = new SolidColorBrush(Color.FromArgb(255, 51, 51, 51));
        private SolidColorBrush LegendOn = new SolidColorBrush(Color.FromArgb(255, 51, 51, 51));
        private SolidColorBrush LegendOff = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
        private SolidColorBrush LegendOffText = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
        private SolidColorBrush LegendOnHoverText = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));

        /// <summary>
        /// Lists all obesity data for all states, on year-by-year basis from 1987-2007
        /// </summary>
        Dictionary<int, State[]> Years = new Dictionary<int, State[]>();

        Dictionary<string, string> StateLabels = new Dictionary<string, string>();

        // this following two lists are used to provide 
        // some test data for the demo
        private List<string> States = new List<string>();
        private List<int> ObesityRates = new List<int>();

        public Page()
        {
            InitializeComponent();
            InitializeStateLabels();

            // legend button event listeners
            Category1Mouse.MouseEnter += new MouseEventHandler(Category1Mouse_MouseEnter);
            Category1Mouse.MouseLeave += new MouseEventHandler(Category1Mouse_MouseLeave);
            Category2Mouse.MouseEnter += new MouseEventHandler(Category2Mouse_MouseEnter);
            Category2Mouse.MouseLeave += new MouseEventHandler(Category2Mouse_MouseLeave);
            Category3Mouse.MouseEnter += new MouseEventHandler(Category3Mouse_MouseEnter);
            Category3Mouse.MouseLeave += new MouseEventHandler(Category3Mouse_MouseLeave);
            Category4Mouse.MouseEnter += new MouseEventHandler(Category4Mouse_MouseEnter);
            Category4Mouse.MouseLeave += new MouseEventHandler(Category4Mouse_MouseLeave);
            Category5Mouse.MouseEnter += new MouseEventHandler(Category5Mouse_MouseEnter);
            Category5Mouse.MouseLeave += new MouseEventHandler(Category5Mouse_MouseLeave);
            Category6Mouse.MouseEnter += new MouseEventHandler(Category6Mouse_MouseEnter);
            Category6Mouse.MouseLeave += new MouseEventHandler(Category6Mouse_MouseLeave);
            Category7Mouse.MouseEnter += new MouseEventHandler(Category7Mouse_MouseEnter);
            Category7Mouse.MouseLeave += new MouseEventHandler(Category7Mouse_MouseLeave);
            Category1Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category1Mouse_MouseLeftButtonUp);
            Category2Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category2Mouse_MouseLeftButtonUp);
            Category3Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category3Mouse_MouseLeftButtonUp);
            Category4Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category4Mouse_MouseLeftButtonUp);
            Category5Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category5Mouse_MouseLeftButtonUp);
            Category6Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category6Mouse_MouseLeftButtonUp);
            Category7Mouse.MouseLeftButtonUp += new MouseButtonEventHandler(Category7Mouse_MouseLeftButtonUp);

            // radio button event listeners
            radioDescending.Click += new RoutedEventHandler(radioDescending_Click);
            radioAscending.Click += new RoutedEventHandler(radioAscending_Click);
            radioObesityRate.Click += new RoutedEventHandler(radioObesityRate_Click);
            radioAlphabetical.Click += new RoutedEventHandler(radioAlphabetical_Click);

            sliderYear.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderYear_ValueChanged);

            TimelineTimerStart.Completed += new EventHandler(TimelineTimer_Completed);
            TimelineTimer.Completed += new EventHandler(TimelineTimer_Completed);

            this.Loaded += new RoutedEventHandler(Page_Loaded);
        }

        /// <summary>
        /// Represents the obesity and overweight information for a state
        /// </summary>
        class State
        {
            /// <summary>
            /// The state's abbreviation
            /// </summary>
            public string Abbr;
            /// <summary>
            /// The percentage of the state population who are obese
            /// </summary>
            public double Obesity;
            /// <summary>
            /// The percentage of the state population who are overweight
            /// </summary>
            public double Overweight;
        }

        #region Legend MouseEnter and Leave Events
        /*
         * The following events handle the highlighting and selection of the legend categories
         * For example, 10-20%, or 20-30%
         */
        private void Category1Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category1Selected)
            {
                Category1Highlight.Fill = LegendOff;
                Category1Text.Foreground = LegendOffText;
            }
            else
            {
                Category1Highlight.Fill = LegendOn;
                Category1Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category1Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category1Selected)
            {
                Category1Highlight.Fill = LegendOn;
                Category1Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category1Highlight.Fill = LegendHover;
                Category1Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category2Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category2Selected)
            {
                Category2Highlight.Fill = LegendOff;
                Category2Text.Foreground = LegendOffText;
            }
            else
            {
                Category2Highlight.Fill = LegendOn;
                Category2Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category2Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category2Selected)
            {
                Category2Highlight.Fill = LegendOn;
                Category2Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category2Highlight.Fill = LegendHover;
                Category2Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category3Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category3Selected)
            {
                Category3Highlight.Fill = LegendOff;
                Category3Text.Foreground = LegendOffText;
            }
            else
            {
                Category3Highlight.Fill = LegendOn;
                Category3Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category3Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category3Selected)
            {
                Category3Highlight.Fill = LegendOn;
                Category3Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category3Highlight.Fill = LegendHover;
                Category3Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category4Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category4Selected)
            {
                Category4Highlight.Fill = LegendOff;
                Category4Text.Foreground = LegendOffText;
            }
            else
            {
                Category4Highlight.Fill = LegendOn;
                Category4Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category4Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category4Selected)
            {
                Category4Highlight.Fill = LegendOn;
                Category4Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category4Highlight.Fill = LegendHover;
                Category4Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category5Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category5Selected)
            {
                Category5Highlight.Fill = LegendOff;
                Category5Text.Foreground = LegendOffText;
            }
            else
            {
                Category5Highlight.Fill = LegendOn;
                Category5Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category5Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category5Selected)
            {
                Category5Highlight.Fill = LegendOn;
                Category5Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category5Highlight.Fill = LegendHover;
                Category5Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category6Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category6Selected)
            {
                Category6Highlight.Fill = LegendOff;
                Category6Text.Foreground = LegendOffText;
            }
            else
            {
                Category6Highlight.Fill = LegendOn;
                Category6Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category6Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category6Selected)
            {
                Category6Highlight.Fill = LegendOn;
                Category6Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category6Highlight.Fill = LegendHover;
                Category6Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category7Mouse_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!Category7Selected)
            {
                Category7Highlight.Fill = LegendOff;
                Category7Text.Foreground = LegendOffText;
            }
            else
            {
                Category7Highlight.Fill = LegendOn;
                Category7Text.Foreground = LegendOnHoverText;
            }
        }

        private void Category7Mouse_MouseEnter(object sender, MouseEventArgs e)
        {
            if (Category7Selected)
            {
                Category7Highlight.Fill = LegendOn;
                Category7Text.Foreground = LegendOnHoverText;
            }
            else
            {
                Category7Highlight.Fill = LegendHover;
                Category7Text.Foreground = LegendOnHoverText;
            }
        }
        #endregion Legend MouseEnter and Leave Events


        /// <summary>
        /// When the app first loads, the timeline is animated.  Once animation is finished, the UI is enabled for the user to explore the data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimelineTimer_Completed(object sender, EventArgs e)
        {
            sliderYear.Value++;

            if ((int)sliderYear.Value < 2007)
            {
                TimelineTimer.Begin();
            }
            else
            {
                // slider scan is done, enable interface
                radioAscending.IsEnabled = true;
                radioDescending.IsEnabled = true;
                radioAlphabetical.IsEnabled = true;
                radioObesityRate.IsEnabled = true;
                sliderYear.IsEnabled = true;
                LegendMouse.IsHitTestVisible = true;
            }
        }

        /// <summary>
        /// When the user moves to a different year, we need to re-paint the T-shirts and draw the HTML chart
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sliderYear_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Dispatcher.BeginInvoke(delegate()
            {

                ClearTextBold();

                sliderYear.ValueChanged-=new RoutedPropertyChangedEventHandler<double>(sliderYear_ValueChanged);
                sliderYear.Value = Math.Round(e.NewValue);
                sliderYear.ValueChanged+= new RoutedPropertyChangedEventHandler<double>(sliderYear_ValueChanged);
                int YearValue = (int)Math.Round(e.NewValue);

                var SelectedYear = Years[YearValue];

                // clear existing highlighted items
                ClearAllTeeHighlights();

                for (int i = 0; i < AllTees.Count(); i++)
                {
                    AllTees[i].MsgState.Text = SelectedYear[i].Abbr.ToString();
                    AllTees[i].MsgObesity.Text = SelectedYear[i].Obesity.ToString();
                    AllTees[i].ObesityRate = (double)SelectedYear[i].Obesity;

                    AllTees[i].SetTeeState();
                    AllTees[i].ChangeTee(AllTees[i].currentState);
                }

                switch ((int)sliderYear.Value)
                {
                    case 1987:
                        txt1987.FontWeight = FontWeights.Bold;
                        txt1987.FontSize = 11;
                        break;
                    case 1988:
                        txt1988.FontWeight = FontWeights.Bold;
                        txt1988.FontSize = 11;
                        break;
                    case 1989:
                        txt1989.FontWeight = FontWeights.Bold;
                        txt1989.FontSize = 11;
                        break;
                    case 1990:
                        txt1990.FontWeight = FontWeights.Bold;
                        txt1990.FontSize = 11;
                        break;
                    case 1991:
                        txt1991.FontWeight = FontWeights.Bold;
                        txt1991.FontSize = 11;
                        break;
                    case 1992:
                        txt1992.FontWeight = FontWeights.Bold;
                        txt1992.FontSize = 11;
                        break;
                    case 1993:
                        txt1993.FontWeight = FontWeights.Bold;
                        txt1993.FontSize = 11;
                        break;
                    case 1994:
                        txt1994.FontWeight = FontWeights.Bold;
                        txt1994.FontSize = 11;
                        break;
                    case 1995:
                        txt1995.FontWeight = FontWeights.Bold;
                        txt1995.FontSize = 11;
                        break;
                    case 1996:
                        txt1996.FontWeight = FontWeights.Bold;
                        txt1996.FontSize = 11;
                        break;
                    case 1997:
                        txt1997.FontWeight = FontWeights.Bold;
                        txt1997.FontSize = 11;
                        break;
                    case 1998:
                        txt1998.FontWeight = FontWeights.Bold;
                        txt1998.FontSize = 11;
                        break;
                    case 1999:
                        txt1999.FontWeight = FontWeights.Bold;
                        txt1999.FontSize = 11;
                        break;
                    case 2000:
                        txt2000.FontWeight = FontWeights.Bold;
                        txt2000.FontSize = 11;
                        break;
                    case 2001:
                        txt2001.FontWeight = FontWeights.Bold;
                        txt2001.FontSize = 11;
                        break;
                    case 2002:
                        txt2002.FontWeight = FontWeights.Bold;
                        txt2002.FontSize = 11;
                        break;
                    case 2003:
                        txt2003.FontWeight = FontWeights.Bold;
                        txt2003.FontSize = 11;
                        break;
                    case 2004:
                        txt2004.FontWeight = FontWeights.Bold;
                        txt2004.FontSize = 11;
                        break;
                    case 2005:
                        txt2005.FontWeight = FontWeights.Bold;
                        txt2005.FontSize = 11;
                        break;
                    case 2006:
                        txt2006.FontWeight = FontWeights.Bold;
                        txt2006.FontSize = 11;
                        break;
                    case 2007:
                        txt2007.FontWeight = FontWeights.Bold;
                        txt2007.FontSize = 11;
                        break;
                }

                if (Category1Selected) { DoCategory1Highlights(); }
                else if (Category2Selected) { DoCategory2Highlights(); }
                else if (Category3Selected) { DoCategory3Highlights(); }
                else if (Category4Selected) { DoCategory4Highlights(); }
                else if (Category5Selected) { DoCategory5Highlights(); }
                else if (Category6Selected) { DoCategory6Highlights(); }
                else if (Category7Selected) { DoCategory7Highlights(); }

                setDOM("year", YearValue.ToString());
                setDOM("bar-chart", StatesTable(YearValue).ToString());
            }
            );
        }

        /// <summary>
        /// Once the page loads, start loading the XML file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Uri dataFile = new Uri(Application.Current.Host.Source, "out.xml");
            WebClient rest = new WebClient();
            rest.DownloadStringCompleted += new DownloadStringCompletedEventHandler(rest_DownloadStringCompleted);
            rest.DownloadStringAsync(dataFile);
        }

        /// <summary>
        /// The XML file is downloaded, so parse it into Years dictionary and paint the T-shirts, then kick off the timeline animation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            var doc = XDocument.Parse(e.Result);

            var yearsdata = from dataRow in doc.Descendants("data")
                            select new
                            {
                                year = dataRow.Attribute("year").Value,
                                states =
                                  from stateRow in dataRow.Elements("state")
                                  where stateRow.Attribute("abbrev").Value != "XX"
                                        && stateRow.Attribute("abbrev").Value != "DC"
                                        && stateRow.Attribute("abbrev").Value != "AS"
                                        && stateRow.Attribute("abbrev").Value != "GU"
                                        && stateRow.Attribute("abbrev").Value != "PR"
                                        && stateRow.Attribute("abbrev").Value != "VI"
                                  orderby stateRow.Attribute("abbrev").Value
                                  select new State
                                  {
                                      Abbr = stateRow.Attribute("abbrev").Value,
                                      Obesity = Convert.ToDouble(stateRow.Attribute("obese").Value),
                                      Overweight = Convert.ToDouble(stateRow.Attribute("overweight").Value)
                                  }
                            };

            foreach (var yeardata in yearsdata) Years.Add(Convert.ToInt32(yeardata.year), yeardata.states.ToArray());

            PopulatePoints();
            InitializeTees();

            foreach (tee t in AllTees)
            {
                t.ShowTee.Begin();
            }

            TimelineTimerStart.Begin();

        }

        // *************************************
        // * The radioAlphabetical_Click event
        // * handler contains code to handle 
        // * necessary actions when the alphabetical
        // * radio button has been clicked.
        // *************************************
        private void radioAlphabetical_Click(object sender, RoutedEventArgs e)
        {
            ObesityRadioIsChecked = false;
            if (AlphabeticalRadioIsChecked) return;

            // sort ascending by state
            if (radioAscending.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t1.MsgState.Text.CompareTo(t2.MsgState.Text); });

                // Sort all years by state abbreviation ascending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Abbr ascending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
            }

            // sort descending by state
            else if (radioDescending.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t2.MsgState.Text.CompareTo(t1.MsgState.Text); });

                // Sort all years by state abbreviation descending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Abbr descending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
            }

            SetTeeStoryboardTargets();
            ResetTeeObjectCoordinates();

            UpdateStoryboardCoordinates();
            PlayMoveTeeStoryboards();

            AlphabeticalRadioIsChecked = true;
        }

        // *************************************
        // * The radioObesityRate_Click event
        // * handler contains code to handle 
        // * necessary actions when the obesity
        // * radio button has been clicked.
        // *************************************
        private void radioObesityRate_Click(object sender, RoutedEventArgs e)
        {
            AlphabeticalRadioIsChecked = false;
            if (ObesityRadioIsChecked) return;

            // sort ascending obesity rate
            if (radioAscending.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t1.ObesityRate.CompareTo(t2.ObesityRate); });

                // Sort all years by obesity ascending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Obesity ascending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
            }

            // sort descending obesity rate
            else if (radioDescending.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t2.ObesityRate.CompareTo(t1.ObesityRate); });

                // Sort all years by obesity descending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Obesity descending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }

            }

            SetObesityStoryboardTargets();
            ResetTeeObjectCoordinates();
            UpdateObesityStoryboardCoordinates();
            PlayObesityMoveTeeStoryboards();

            ObesityRadioIsChecked = true;
        }

        // *************************************
        // * The radioAscending_Click event
        // * handler contains code to handle 
        // * necessary actions when the ascending
        // * radio button has been clicked.
        // *************************************
        private void radioAscending_Click(object sender, RoutedEventArgs e)
        {
            DescendingRadioIsChecked = false;
            if (AscendingRadioIsChecked) return;

            // sort ascending alphabetical
            if (radioAlphabetical.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t1.MsgState.Text.CompareTo(t2.MsgState.Text); });
                // Sort all years by state abbreviation ascending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Abbr ascending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
                UpdateStoryboardCoordinates();
                PlayMoveTeeStoryboards();
            }

            // sort ascending obesity rate
            else if (radioObesityRate.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t2.ObesityRate.CompareTo(t1.ObesityRate); });

                // Sort all years by obesity ascending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Obesity ascending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
                UpdateObesityStoryboardCoordinates();
                PlayObesityMoveTeeStoryboards();
            }

            AscendingRadioIsChecked = true;
        }

        // *************************************
        // * The radioDescending_Click event
        // * handler contains code to handle 
        // * necessary actions when the descending
        // * radio button has been clicked.
        // *************************************
        private void radioDescending_Click(object sender, RoutedEventArgs e)
        {
            AscendingRadioIsChecked = false;
            if (DescendingRadioIsChecked) return;

            // sort descending alphabetical
            if (radioAlphabetical.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t2.MsgState.Text.CompareTo(t1.MsgState.Text); });
                // Sort all years by state abbreviation descending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Abbr descending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
                UpdateStoryboardCoordinates();
                PlayMoveTeeStoryboards();
            }

            // sort descending obesity rate
            else if (radioObesityRate.IsChecked == true)
            {
                AllTees.Sort(delegate(tee t1, tee t2) { return t2.ObesityRate.CompareTo(t1.ObesityRate); });

                // Sort all years by obesity descending
                for (int year = 1987; year <= 2007; year++) // Sort every year
                {
                    State[] states = Years[year];
                    var sortedStates = from state in states
                                       orderby state.Obesity descending
                                       select state;

                    Years[year] = sortedStates.ToArray();
                }
                UpdateObesityStoryboardCoordinates();
                PlayObesityMoveTeeStoryboards();
            }

            DescendingRadioIsChecked = true;
        }


        #region LegendClickedEvents
        /*
         * This section contains event handlers for legend clicks
         */
        private void ClearAllTeeHighlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                TeeItem.RemoveHighlightPanel.Begin();
            }
        }

        private void ClearLegendHighlights()
        {
            Category1Highlight.Fill =
            Category2Highlight.Fill =
            Category3Highlight.Fill =
            Category4Highlight.Fill =
            Category5Highlight.Fill =
            Category6Highlight.Fill =
            Category7Highlight.Fill = LegendOff;

            Category1Text.Foreground =
            Category2Text.Foreground =
            Category3Text.Foreground =
            Category4Text.Foreground =
            Category5Text.Foreground =
            Category6Text.Foreground =
            Category7Text.Foreground = LegendOffText;
        }

        // category 1 - "No Data" selected
        private void Category1Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();
            ClearLegendHighlights();

            if (Category1Selected)
            {
                ClearAllTeeHighlights();
                Category1Selected = false;

                return;
            }

            Category1Highlight.Visibility = Visibility.Visible;
            Category1Highlight.Fill = LegendOn;
            Category1Text.Foreground = LegendOnHoverText;

            DoCategory1Highlights();

            Category1Selected = true;
            Category2Selected = false;
            Category3Selected = false;
            Category4Selected = false;
            Category5Selected = false;
            Category6Selected = false;
            Category7Selected = false;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());

        }

        private void DoCategory1Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate == 0)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }

        // category 2 - "< 10%" selected
        private void Category2Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();

            ClearLegendHighlights();

            if (Category2Selected)
            {
                ClearAllTeeHighlights();
                Category2Selected = false;

                return;
            }

            Category2Highlight.Visibility = Visibility.Visible;
            Category2Highlight.Fill = LegendOn;
            Category2Text.Foreground = LegendOnHoverText;

            DoCategory2Highlights();

            Category1Selected = false;
            Category2Selected = true;
            Category3Selected = false;
            Category4Selected = false;
            Category5Selected = false;
            Category6Selected = false;
            Category7Selected = false;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());
        }

        private void DoCategory2Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate >= 1 && TeeItem.ObesityRate < 10)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }

        // category 3 - "10 - 14%" selected
        private void Category3Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();

            ClearLegendHighlights();

            if (Category3Selected)
            {
                ClearAllTeeHighlights();
                Category3Selected = false;

                return;
            }

            Category3Highlight.Visibility = Visibility.Visible;
            Category3Highlight.Fill = LegendOn;
            Category3Text.Foreground = LegendOnHoverText;

            DoCategory3Highlights();


            Category1Selected = false;
            Category2Selected = false;
            Category3Selected = true;
            Category4Selected = false;
            Category5Selected = false;
            Category6Selected = false;
            Category7Selected = false;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());
        }

        private void DoCategory3Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate >= 10 && TeeItem.ObesityRate < 15)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }
        // category 4 - "15 - 19%" selected
        private void Category4Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();
            ClearLegendHighlights();

            if (Category4Selected)
            {
                ClearAllTeeHighlights();
                Category4Selected = false;

                return;
            }

            Category4Highlight.Visibility = Visibility.Visible;
            Category4Highlight.Fill = LegendOn;
            Category4Text.Foreground = LegendOnHoverText;

            DoCategory4Highlights();

            Category1Selected = false;
            Category2Selected = false;
            Category3Selected = false;
            Category4Selected = true;
            Category5Selected = false;
            Category6Selected = false;
            Category7Selected = false;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());
        }

        private void DoCategory4Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate >= 15 && TeeItem.ObesityRate < 20)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }

        // category 5 - "20 - 24%" selected
        private void Category5Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();
            ClearLegendHighlights();

            if (Category5Selected)
            {
                ClearAllTeeHighlights();
                Category5Selected = false;

                return;
            }

            Category5Highlight.Visibility = Visibility.Visible;
            Category5Highlight.Fill = LegendOn;
            Category5Text.Foreground = LegendOnHoverText;

            DoCategory5Highlights();

            Category1Selected = false;
            Category2Selected = false;
            Category3Selected = false;
            Category4Selected = false;
            Category5Selected = true;
            Category6Selected = false;
            Category7Selected = false;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());
        }

        private void DoCategory5Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate >= 20 && TeeItem.ObesityRate < 25)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }

        // category 6 - "25 - 30%" selected
        private void Category6Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();
            ClearLegendHighlights();

            if (Category6Selected)
            {
                ClearAllTeeHighlights();
                Category6Selected = false;

                return;
            }

            Category6Highlight.Visibility = Visibility.Visible;
            Category6Highlight.Fill = LegendOn;
            Category6Text.Foreground = LegendOnHoverText;

            DoCategory6Highlights();

            Category1Selected = false;
            Category2Selected = false;
            Category3Selected = false;
            Category4Selected = false;
            Category5Selected = false;
            Category6Selected = true;
            Category7Selected = false;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());
        }

        private void DoCategory6Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate >= 25 && TeeItem.ObesityRate <= 30)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }

        // category 7 - "> 30%" selected
        private void Category7Mouse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TimelineTimer.Stop();
            ClearLegendHighlights();

            if (Category7Selected)
            {
                ClearAllTeeHighlights();
                Category7Selected = false;

                return;
            }

            Category7Highlight.Visibility = Visibility.Visible;
            Category7Highlight.Fill = LegendOn;
            Category7Text.Foreground = LegendOnHoverText;

            DoCategory7Highlights();

            Category1Selected = false;
            Category2Selected = false;
            Category3Selected = false;
            Category4Selected = false;
            Category5Selected = false;
            Category6Selected = false;
            Category7Selected = true;

            int YearValue = (int)Math.Round(sliderYear.Value);
            setDOM("bar-chart", StatesTable(YearValue).ToString());
        }

        private void DoCategory7Highlights()
        {
            foreach (tee TeeItem in AllTees)
            {
                if (TeeItem.ObesityRate > 30)
                {
                    TeeItem.HighlightPanel.Begin();
                }
                else
                {
                    TeeItem.RemoveHighlightPanel.Begin();
                }
            }
        }

        #endregion LegendClickedEvents

        // *************************************
        // * The InitializeTees method generates
        // * the 50 tee objects and places them
        // * on the TeeCanvas when the app loads.
        // *************************************
        private void InitializeTees()
        {
            int ShowTimerMilliseconds = 2200;
            int dataCounter = 0;

            foreach (Point p in TeeLocations)
            {
                tee NewTee = new tee();
                Canvas.SetLeft(NewTee, p.X);
                Canvas.SetTop(NewTee, p.Y);
                NewTee.TeeLeft = p.X;
                NewTee.TeeTop = p.Y;
                NewTee.MsgState.Text = Years[1987][dataCounter].Abbr;
                NewTee.MsgObesity.Text = Years[1987][dataCounter].Obesity.ToString();
                NewTee.ObesityRate = (double)Years[1987][dataCounter].Obesity;
                AllTees.Add(NewTee);
                TeeCanvas.Children.Add(NewTee);
                dataCounter++;

                // the following three lines do the intro load animation
                // remove them to create a static 50 tee display onload
                NewTee.LayoutRoot.Opacity = 0;
                NewTee.DelayShowStart.BeginTime = TimeSpan.FromMilliseconds(ShowTimerMilliseconds);
                ShowTimerMilliseconds += 25;
            }

            SetTeeStoryboardTargets();
            UpdateStoryboardCoordinates();
        }

        /// <summary>
        /// Helper method to set innerHTML property of HTML DOM node
        /// </summary>
        /// <param name="id">The id of the HTML DOM node to target</param>
        /// <param name="innerHTML">The new innerHTML, in string format</param>
        /// <remarks>No error is thrown if the node doesn't exist</remarks>
        public void setDOM(string id, string innerHTML)
        {
            try
            {
                var doc = HtmlPage.Document;
                var node = doc.GetElementById(id);
                if (node != null) node.SetProperty("innerHTML", innerHTML);
            }
            catch (Exception e) { }
        }


        private void SetTeeStoryboardTargets()
        {
            MoveTee0.Stop();
            MoveTee1.Stop();
            MoveTee2.Stop();
            MoveTee3.Stop();
            MoveTee4.Stop();
            MoveTee5.Stop();
            MoveTee6.Stop();
            MoveTee7.Stop();
            MoveTee8.Stop();
            MoveTee9.Stop();
            MoveTee10.Stop();

            MoveTee11.Stop();
            MoveTee12.Stop();
            MoveTee13.Stop();
            MoveTee14.Stop();
            MoveTee15.Stop();
            MoveTee16.Stop();
            MoveTee17.Stop();
            MoveTee18.Stop();
            MoveTee19.Stop();
            MoveTee20.Stop();

            MoveTee21.Stop();
            MoveTee22.Stop();
            MoveTee23.Stop();
            MoveTee24.Stop();
            MoveTee25.Stop();
            MoveTee26.Stop();
            MoveTee27.Stop();
            MoveTee28.Stop();
            MoveTee29.Stop();
            MoveTee30.Stop();

            MoveTee31.Stop();
            MoveTee32.Stop();
            MoveTee33.Stop();
            MoveTee34.Stop();
            MoveTee35.Stop();
            MoveTee36.Stop();
            MoveTee37.Stop();
            MoveTee38.Stop();
            MoveTee39.Stop();
            MoveTee40.Stop();

            MoveTee41.Stop();
            MoveTee42.Stop();
            MoveTee43.Stop();
            MoveTee44.Stop();
            MoveTee45.Stop();
            MoveTee46.Stop();
            MoveTee47.Stop();
            MoveTee48.Stop();
            MoveTee49.Stop();

            // set up storyboard targets
            Storyboard.SetTarget(MoveTee0, AllTees[0]);
            Storyboard.SetTarget(MoveTee1, AllTees[1]);
            Storyboard.SetTarget(MoveTee2, AllTees[2]);
            Storyboard.SetTarget(MoveTee3, AllTees[3]);
            Storyboard.SetTarget(MoveTee4, AllTees[4]);
            Storyboard.SetTarget(MoveTee5, AllTees[5]);
            Storyboard.SetTarget(MoveTee6, AllTees[6]);
            Storyboard.SetTarget(MoveTee7, AllTees[7]);
            Storyboard.SetTarget(MoveTee8, AllTees[8]);
            Storyboard.SetTarget(MoveTee9, AllTees[9]);
            Storyboard.SetTarget(MoveTee10, AllTees[10]);
            Storyboard.SetTarget(MoveTee11, AllTees[11]);
            Storyboard.SetTarget(MoveTee12, AllTees[12]);
            Storyboard.SetTarget(MoveTee13, AllTees[13]);
            Storyboard.SetTarget(MoveTee14, AllTees[14]);
            Storyboard.SetTarget(MoveTee15, AllTees[15]);
            Storyboard.SetTarget(MoveTee16, AllTees[16]);
            Storyboard.SetTarget(MoveTee17, AllTees[17]);
            Storyboard.SetTarget(MoveTee18, AllTees[18]);
            Storyboard.SetTarget(MoveTee19, AllTees[19]);
            Storyboard.SetTarget(MoveTee20, AllTees[20]);
            Storyboard.SetTarget(MoveTee21, AllTees[21]);
            Storyboard.SetTarget(MoveTee22, AllTees[22]);
            Storyboard.SetTarget(MoveTee23, AllTees[23]);
            Storyboard.SetTarget(MoveTee24, AllTees[24]);
            Storyboard.SetTarget(MoveTee25, AllTees[25]);
            Storyboard.SetTarget(MoveTee26, AllTees[26]);
            Storyboard.SetTarget(MoveTee27, AllTees[27]);
            Storyboard.SetTarget(MoveTee28, AllTees[28]);
            Storyboard.SetTarget(MoveTee29, AllTees[29]);
            Storyboard.SetTarget(MoveTee30, AllTees[30]);
            Storyboard.SetTarget(MoveTee31, AllTees[31]);
            Storyboard.SetTarget(MoveTee32, AllTees[32]);
            Storyboard.SetTarget(MoveTee33, AllTees[33]);
            Storyboard.SetTarget(MoveTee34, AllTees[34]);
            Storyboard.SetTarget(MoveTee35, AllTees[35]);
            Storyboard.SetTarget(MoveTee36, AllTees[36]);
            Storyboard.SetTarget(MoveTee37, AllTees[37]);
            Storyboard.SetTarget(MoveTee38, AllTees[38]);
            Storyboard.SetTarget(MoveTee39, AllTees[39]);
            Storyboard.SetTarget(MoveTee40, AllTees[40]);
            Storyboard.SetTarget(MoveTee41, AllTees[41]);
            Storyboard.SetTarget(MoveTee42, AllTees[42]);
            Storyboard.SetTarget(MoveTee43, AllTees[43]);
            Storyboard.SetTarget(MoveTee44, AllTees[44]);
            Storyboard.SetTarget(MoveTee45, AllTees[45]);
            Storyboard.SetTarget(MoveTee46, AllTees[46]);
            Storyboard.SetTarget(MoveTee47, AllTees[47]);
            Storyboard.SetTarget(MoveTee48, AllTees[48]);
            Storyboard.SetTarget(MoveTee49, AllTees[49]);
        }

        // *************************************
        // * The SetObesityStoryboardTargets 
        // * method is used to set the storyboard
        // * targets for the storyboards run when
        // * obesity is selected.
        // *************************************
        private void SetObesityStoryboardTargets()
        {
            MoveTee0a.Stop();
            MoveTee1a.Stop();
            MoveTee2a.Stop();
            MoveTee3a.Stop();
            MoveTee4a.Stop();
            MoveTee5a.Stop();
            MoveTee6a.Stop();
            MoveTee7a.Stop();
            MoveTee8a.Stop();
            MoveTee9a.Stop();
            MoveTee10a.Stop();

            MoveTee11a.Stop();
            MoveTee12a.Stop();
            MoveTee13a.Stop();
            MoveTee14a.Stop();
            MoveTee15a.Stop();
            MoveTee16a.Stop();
            MoveTee17a.Stop();
            MoveTee18a.Stop();
            MoveTee19a.Stop();
            MoveTee20a.Stop();

            MoveTee21a.Stop();
            MoveTee22a.Stop();
            MoveTee23a.Stop();
            MoveTee24a.Stop();
            MoveTee25a.Stop();
            MoveTee26a.Stop();
            MoveTee27a.Stop();
            MoveTee28a.Stop();
            MoveTee29a.Stop();
            MoveTee30a.Stop();

            MoveTee31a.Stop();
            MoveTee32a.Stop();
            MoveTee33a.Stop();
            MoveTee34a.Stop();
            MoveTee35a.Stop();
            MoveTee36a.Stop();
            MoveTee37a.Stop();
            MoveTee38a.Stop();
            MoveTee39a.Stop();
            MoveTee40a.Stop();

            MoveTee41a.Stop();
            MoveTee42a.Stop();
            MoveTee43a.Stop();
            MoveTee44a.Stop();
            MoveTee45a.Stop();
            MoveTee46a.Stop();
            MoveTee47a.Stop();
            MoveTee48a.Stop();
            MoveTee49a.Stop();

            Storyboard.SetTarget(MoveTee0a, AllTees[0]);
            Storyboard.SetTarget(MoveTee1a, AllTees[1]);
            Storyboard.SetTarget(MoveTee2a, AllTees[2]);
            Storyboard.SetTarget(MoveTee3a, AllTees[3]);
            Storyboard.SetTarget(MoveTee4a, AllTees[4]);
            Storyboard.SetTarget(MoveTee5a, AllTees[5]);
            Storyboard.SetTarget(MoveTee6a, AllTees[6]);
            Storyboard.SetTarget(MoveTee7a, AllTees[7]);
            Storyboard.SetTarget(MoveTee8a, AllTees[8]);
            Storyboard.SetTarget(MoveTee9a, AllTees[9]);
            Storyboard.SetTarget(MoveTee10a, AllTees[10]);
            Storyboard.SetTarget(MoveTee11a, AllTees[11]);
            Storyboard.SetTarget(MoveTee12a, AllTees[12]);
            Storyboard.SetTarget(MoveTee13a, AllTees[13]);
            Storyboard.SetTarget(MoveTee14a, AllTees[14]);
            Storyboard.SetTarget(MoveTee15a, AllTees[15]);
            Storyboard.SetTarget(MoveTee16a, AllTees[16]);
            Storyboard.SetTarget(MoveTee17a, AllTees[17]);
            Storyboard.SetTarget(MoveTee18a, AllTees[18]);
            Storyboard.SetTarget(MoveTee19a, AllTees[19]);
            Storyboard.SetTarget(MoveTee20a, AllTees[20]);
            Storyboard.SetTarget(MoveTee21a, AllTees[21]);
            Storyboard.SetTarget(MoveTee22a, AllTees[22]);
            Storyboard.SetTarget(MoveTee23a, AllTees[23]);
            Storyboard.SetTarget(MoveTee24a, AllTees[24]);
            Storyboard.SetTarget(MoveTee25a, AllTees[25]);
            Storyboard.SetTarget(MoveTee26a, AllTees[26]);
            Storyboard.SetTarget(MoveTee27a, AllTees[27]);
            Storyboard.SetTarget(MoveTee28a, AllTees[28]);
            Storyboard.SetTarget(MoveTee29a, AllTees[29]);
            Storyboard.SetTarget(MoveTee30a, AllTees[30]);
            Storyboard.SetTarget(MoveTee31a, AllTees[31]);
            Storyboard.SetTarget(MoveTee32a, AllTees[32]);
            Storyboard.SetTarget(MoveTee33a, AllTees[33]);
            Storyboard.SetTarget(MoveTee34a, AllTees[34]);
            Storyboard.SetTarget(MoveTee35a, AllTees[35]);
            Storyboard.SetTarget(MoveTee36a, AllTees[36]);
            Storyboard.SetTarget(MoveTee37a, AllTees[37]);
            Storyboard.SetTarget(MoveTee38a, AllTees[38]);
            Storyboard.SetTarget(MoveTee39a, AllTees[39]);
            Storyboard.SetTarget(MoveTee40a, AllTees[40]);
            Storyboard.SetTarget(MoveTee41a, AllTees[41]);
            Storyboard.SetTarget(MoveTee42a, AllTees[42]);
            Storyboard.SetTarget(MoveTee43a, AllTees[43]);
            Storyboard.SetTarget(MoveTee44a, AllTees[44]);
            Storyboard.SetTarget(MoveTee45a, AllTees[45]);
            Storyboard.SetTarget(MoveTee46a, AllTees[46]);
            Storyboard.SetTarget(MoveTee47a, AllTees[47]);
            Storyboard.SetTarget(MoveTee48a, AllTees[48]);
            Storyboard.SetTarget(MoveTee49a, AllTees[49]);
        }

        // *************************************
        // * The SetObesityStoryboardCoordinates 
        // * method is used to update the storyboard
        // * coordinates that move each tee around
        // * based on various user input when the
        // * obesity checkbox is selected
        // *************************************
        private void UpdateObesityStoryboardCoordinates()
        {
            MoveToX0a.To = AllTees[0].TeeLeft;
            MoveToY0a.To = AllTees[0].TeeTop;
            MoveToX1a.To = AllTees[1].TeeLeft;
            MoveToY1a.To = AllTees[1].TeeTop;
            MoveToX2a.To = AllTees[2].TeeLeft;
            MoveToY2a.To = AllTees[2].TeeTop;
            MoveToX3a.To = AllTees[3].TeeLeft;
            MoveToY3a.To = AllTees[3].TeeTop;
            MoveToX4a.To = AllTees[4].TeeLeft;
            MoveToY4a.To = AllTees[4].TeeTop;
            MoveToX5a.To = AllTees[5].TeeLeft;
            MoveToY5a.To = AllTees[5].TeeTop;
            MoveToX6a.To = AllTees[6].TeeLeft;
            MoveToY6a.To = AllTees[6].TeeTop;
            MoveToX7a.To = AllTees[7].TeeLeft;
            MoveToY7a.To = AllTees[7].TeeTop;
            MoveToX8a.To = AllTees[8].TeeLeft;
            MoveToY8a.To = AllTees[8].TeeTop;
            MoveToX9a.To = AllTees[9].TeeLeft;
            MoveToY9a.To = AllTees[9].TeeTop;

            MoveToX10a.To = AllTees[10].TeeLeft;
            MoveToY10a.To = AllTees[10].TeeTop;
            MoveToX11a.To = AllTees[11].TeeLeft;
            MoveToY11a.To = AllTees[11].TeeTop;
            MoveToX12a.To = AllTees[12].TeeLeft;
            MoveToY12a.To = AllTees[12].TeeTop;
            MoveToX13a.To = AllTees[13].TeeLeft;
            MoveToY13a.To = AllTees[13].TeeTop;
            MoveToX14a.To = AllTees[14].TeeLeft;
            MoveToY14a.To = AllTees[14].TeeTop;
            MoveToX15a.To = AllTees[15].TeeLeft;
            MoveToY15a.To = AllTees[15].TeeTop;
            MoveToX16a.To = AllTees[16].TeeLeft;
            MoveToY16a.To = AllTees[16].TeeTop;
            MoveToX17a.To = AllTees[17].TeeLeft;
            MoveToY17a.To = AllTees[17].TeeTop;
            MoveToX18a.To = AllTees[18].TeeLeft;
            MoveToY18a.To = AllTees[18].TeeTop;

            MoveToX19a.To = AllTees[19].TeeLeft;
            MoveToY19a.To = AllTees[19].TeeTop;
            MoveToX20a.To = AllTees[20].TeeLeft;
            MoveToY20a.To = AllTees[20].TeeTop;
            MoveToX21a.To = AllTees[21].TeeLeft;
            MoveToY21a.To = AllTees[21].TeeTop;
            MoveToX22a.To = AllTees[22].TeeLeft;
            MoveToY22a.To = AllTees[22].TeeTop;
            MoveToX23a.To = AllTees[23].TeeLeft;
            MoveToY23a.To = AllTees[23].TeeTop;
            MoveToX24a.To = AllTees[24].TeeLeft;
            MoveToY24a.To = AllTees[24].TeeTop;
            MoveToX25a.To = AllTees[25].TeeLeft;
            MoveToY25a.To = AllTees[25].TeeTop;
            MoveToX26a.To = AllTees[26].TeeLeft;
            MoveToY26a.To = AllTees[26].TeeTop;
            MoveToX27a.To = AllTees[27].TeeLeft;
            MoveToY27a.To = AllTees[27].TeeTop;
            MoveToX28a.To = AllTees[28].TeeLeft;
            MoveToY28a.To = AllTees[28].TeeTop;

            MoveToX29a.To = AllTees[29].TeeLeft;
            MoveToY29a.To = AllTees[29].TeeTop;
            MoveToX30a.To = AllTees[30].TeeLeft;
            MoveToY30a.To = AllTees[30].TeeTop;
            MoveToX31a.To = AllTees[31].TeeLeft;
            MoveToY31a.To = AllTees[31].TeeTop;
            MoveToX32a.To = AllTees[32].TeeLeft;
            MoveToY32a.To = AllTees[32].TeeTop;
            MoveToX33a.To = AllTees[33].TeeLeft;
            MoveToY33a.To = AllTees[33].TeeTop;
            MoveToX34a.To = AllTees[34].TeeLeft;
            MoveToY34a.To = AllTees[34].TeeTop;
            MoveToX35a.To = AllTees[35].TeeLeft;
            MoveToY35a.To = AllTees[35].TeeTop;
            MoveToX36a.To = AllTees[36].TeeLeft;
            MoveToY36a.To = AllTees[36].TeeTop;
            MoveToX37a.To = AllTees[37].TeeLeft;
            MoveToY37a.To = AllTees[37].TeeTop;
            MoveToX38a.To = AllTees[38].TeeLeft;
            MoveToY38a.To = AllTees[38].TeeTop;
            MoveToX39a.To = AllTees[39].TeeLeft;
            MoveToY39a.To = AllTees[39].TeeTop;

            MoveToX40a.To = AllTees[40].TeeLeft;
            MoveToY40a.To = AllTees[40].TeeTop;
            MoveToX41a.To = AllTees[41].TeeLeft;
            MoveToY41a.To = AllTees[41].TeeTop;
            MoveToX42a.To = AllTees[42].TeeLeft;
            MoveToY42a.To = AllTees[42].TeeTop;
            MoveToX43a.To = AllTees[43].TeeLeft;
            MoveToY43a.To = AllTees[43].TeeTop;
            MoveToX44a.To = AllTees[44].TeeLeft;
            MoveToY44a.To = AllTees[44].TeeTop;
            MoveToX45a.To = AllTees[45].TeeLeft;
            MoveToY45a.To = AllTees[45].TeeTop;
            MoveToX46a.To = AllTees[46].TeeLeft;
            MoveToY46a.To = AllTees[46].TeeTop;
            MoveToX47a.To = AllTees[47].TeeLeft;
            MoveToY47a.To = AllTees[47].TeeTop;
            MoveToX48a.To = AllTees[48].TeeLeft;
            MoveToY48a.To = AllTees[48].TeeTop;
            MoveToX49a.To = AllTees[49].TeeLeft;
            MoveToY49a.To = AllTees[49].TeeTop;
        }

        // *************************************
        // * The ResetTeeObjectCoordinates 
        // * method is used to reset all of the
        // * top/left coordinates stored in each
        // * tee object.
        // *************************************
        private void ResetTeeObjectCoordinates()
        {
            for (int i = 0; i <= 49; i++)
            {
                AllTees[i].TeeLeft = TeeLocations[i].X;
                AllTees[i].TeeTop = TeeLocations[i].Y;
            }
        }

        // *************************************
        // * The UpdateStoryboardCoordinates 
        // * method is used to update the storyboard
        // * coordinates that move each tee around
        // * based on various user input. 
        // *************************************
        private void UpdateStoryboardCoordinates()
        {
            MoveToX0.To = AllTees[0].TeeLeft;
            MoveToY0.To = AllTees[0].TeeTop;
            MoveToX1.To = AllTees[1].TeeLeft;
            MoveToY1.To = AllTees[1].TeeTop;
            MoveToX2.To = AllTees[2].TeeLeft;
            MoveToY2.To = AllTees[2].TeeTop;
            MoveToX3.To = AllTees[3].TeeLeft;
            MoveToY3.To = AllTees[3].TeeTop;
            MoveToX4.To = AllTees[4].TeeLeft;
            MoveToY4.To = AllTees[4].TeeTop;
            MoveToX5.To = AllTees[5].TeeLeft;
            MoveToY5.To = AllTees[5].TeeTop;
            MoveToX6.To = AllTees[6].TeeLeft;
            MoveToY6.To = AllTees[6].TeeTop;
            MoveToX7.To = AllTees[7].TeeLeft;
            MoveToY7.To = AllTees[7].TeeTop;
            MoveToX8.To = AllTees[8].TeeLeft;
            MoveToY8.To = AllTees[8].TeeTop;
            MoveToX9.To = AllTees[9].TeeLeft;
            MoveToY9.To = AllTees[9].TeeTop;
            MoveToX10.To = AllTees[10].TeeLeft;
            MoveToY10.To = AllTees[10].TeeTop;
            MoveToX11.To = AllTees[11].TeeLeft;
            MoveToY11.To = AllTees[11].TeeTop;
            MoveToX12.To = AllTees[12].TeeLeft;
            MoveToY12.To = AllTees[12].TeeTop;
            MoveToX13.To = AllTees[13].TeeLeft;
            MoveToY13.To = AllTees[13].TeeTop;
            MoveToX14.To = AllTees[14].TeeLeft;
            MoveToY14.To = AllTees[14].TeeTop;
            MoveToX15.To = AllTees[15].TeeLeft;
            MoveToY15.To = AllTees[15].TeeTop;
            MoveToX16.To = AllTees[16].TeeLeft;
            MoveToY16.To = AllTees[16].TeeTop;
            MoveToX17.To = AllTees[17].TeeLeft;
            MoveToY17.To = AllTees[17].TeeTop;
            MoveToX18.To = AllTees[18].TeeLeft;
            MoveToY18.To = AllTees[18].TeeTop;
            MoveToX19.To = AllTees[19].TeeLeft;
            MoveToY19.To = AllTees[19].TeeTop;

            MoveToX20.To = AllTees[20].TeeLeft;
            MoveToY20.To = AllTees[20].TeeTop;
            MoveToX21.To = AllTees[21].TeeLeft;
            MoveToY21.To = AllTees[21].TeeTop;
            MoveToX22.To = AllTees[22].TeeLeft;
            MoveToY22.To = AllTees[22].TeeTop;
            MoveToX23.To = AllTees[23].TeeLeft;
            MoveToY23.To = AllTees[23].TeeTop;
            MoveToX24.To = AllTees[24].TeeLeft;
            MoveToY24.To = AllTees[24].TeeTop;
            MoveToX25.To = AllTees[25].TeeLeft;
            MoveToY25.To = AllTees[25].TeeTop;
            MoveToX26.To = AllTees[26].TeeLeft;
            MoveToY26.To = AllTees[26].TeeTop;
            MoveToX27.To = AllTees[27].TeeLeft;
            MoveToY27.To = AllTees[27].TeeTop;
            MoveToX28.To = AllTees[28].TeeLeft;
            MoveToY28.To = AllTees[28].TeeTop;
            MoveToX29.To = AllTees[29].TeeLeft;
            MoveToY29.To = AllTees[29].TeeTop;

            MoveToX30.To = AllTees[30].TeeLeft;
            MoveToY30.To = AllTees[30].TeeTop;
            MoveToX31.To = AllTees[31].TeeLeft;
            MoveToY31.To = AllTees[31].TeeTop;
            MoveToX32.To = AllTees[32].TeeLeft;
            MoveToY32.To = AllTees[32].TeeTop;
            MoveToX33.To = AllTees[33].TeeLeft;
            MoveToY33.To = AllTees[33].TeeTop;
            MoveToX34.To = AllTees[34].TeeLeft;
            MoveToY34.To = AllTees[34].TeeTop;
            MoveToX35.To = AllTees[35].TeeLeft;
            MoveToY35.To = AllTees[35].TeeTop;
            MoveToX36.To = AllTees[36].TeeLeft;
            MoveToY36.To = AllTees[36].TeeTop;
            MoveToX37.To = AllTees[37].TeeLeft;
            MoveToY37.To = AllTees[37].TeeTop;
            MoveToX38.To = AllTees[38].TeeLeft;
            MoveToY38.To = AllTees[38].TeeTop;
            MoveToX39.To = AllTees[39].TeeLeft;
            MoveToY39.To = AllTees[39].TeeTop;

            MoveToX40.To = AllTees[40].TeeLeft;
            MoveToY40.To = AllTees[40].TeeTop;
            MoveToX41.To = AllTees[41].TeeLeft;
            MoveToY41.To = AllTees[41].TeeTop;
            MoveToX42.To = AllTees[42].TeeLeft;
            MoveToY42.To = AllTees[42].TeeTop;
            MoveToX43.To = AllTees[43].TeeLeft;
            MoveToY43.To = AllTees[43].TeeTop;
            MoveToX44.To = AllTees[44].TeeLeft;
            MoveToY44.To = AllTees[44].TeeTop;
            MoveToX45.To = AllTees[45].TeeLeft;
            MoveToY45.To = AllTees[45].TeeTop;
            MoveToX46.To = AllTees[46].TeeLeft;
            MoveToY46.To = AllTees[46].TeeTop;
            MoveToX47.To = AllTees[47].TeeLeft;
            MoveToY47.To = AllTees[47].TeeTop;
            MoveToX48.To = AllTees[48].TeeLeft;
            MoveToY48.To = AllTees[48].TeeTop;
            MoveToX49.To = AllTees[49].TeeLeft;
            MoveToY49.To = AllTees[49].TeeTop;
        }

        // *************************************
        // * The PlayObesityMoveTeeStoryboards 
        // * method is used to play all of the 
        // * storyboards when the obesity radio
        // * button has been selected.
        // *************************************
        private void PlayObesityMoveTeeStoryboards()
        {
            MoveTee0a.Begin();
            MoveTee1a.Begin();
            MoveTee2a.Begin();
            MoveTee3a.Begin();
            MoveTee4a.Begin();
            MoveTee5a.Begin();
            MoveTee6a.Begin();
            MoveTee7a.Begin();
            MoveTee8a.Begin();
            MoveTee9a.Begin();
            MoveTee10a.Begin();
            MoveTee11a.Begin();
            MoveTee12a.Begin();
            MoveTee13a.Begin();
            MoveTee14a.Begin();
            MoveTee15a.Begin();
            MoveTee16a.Begin();
            MoveTee17a.Begin();
            MoveTee18a.Begin();
            MoveTee19a.Begin();
            MoveTee20a.Begin();
            MoveTee21a.Begin();
            MoveTee22a.Begin();
            MoveTee23a.Begin();
            MoveTee24a.Begin();
            MoveTee25a.Begin();
            MoveTee26a.Begin();
            MoveTee27a.Begin();
            MoveTee28a.Begin();
            MoveTee29a.Begin();
            MoveTee30a.Begin();
            MoveTee31a.Begin();
            MoveTee32a.Begin();
            MoveTee33a.Begin();
            MoveTee34a.Begin();
            MoveTee35a.Begin();
            MoveTee36a.Begin();
            MoveTee37a.Begin();
            MoveTee38a.Begin();
            MoveTee39a.Begin();
            MoveTee40a.Begin();
            MoveTee41a.Begin();
            MoveTee42a.Begin();
            MoveTee43a.Begin();
            MoveTee44a.Begin();
            MoveTee45a.Begin();
            MoveTee46a.Begin();
            MoveTee47a.Begin();
            MoveTee48a.Begin();
            MoveTee49a.Begin();
        }

        // *************************************
        // * The PlayMoveTeeStoryboards method
        // * plays the storyboards that move all
        // * 50 tee shirt objects
        // *************************************
        private void PlayMoveTeeStoryboards()
        {
            MoveTee0.Begin();
            MoveTee1.Begin();
            MoveTee2.Begin();
            MoveTee3.Begin();
            MoveTee4.Begin();
            MoveTee5.Begin();
            MoveTee6.Begin();
            MoveTee7.Begin();
            MoveTee8.Begin();
            MoveTee9.Begin();
            MoveTee10.Begin();
            MoveTee11.Begin();
            MoveTee12.Begin();
            MoveTee13.Begin();
            MoveTee14.Begin();
            MoveTee15.Begin();
            MoveTee16.Begin();
            MoveTee17.Begin();
            MoveTee18.Begin();
            MoveTee19.Begin();
            MoveTee20.Begin();
            MoveTee21.Begin();
            MoveTee22.Begin();
            MoveTee23.Begin();
            MoveTee24.Begin();
            MoveTee25.Begin();
            MoveTee26.Begin();
            MoveTee27.Begin();
            MoveTee28.Begin();
            MoveTee29.Begin();
            MoveTee30.Begin();
            MoveTee31.Begin();
            MoveTee32.Begin();
            MoveTee33.Begin();
            MoveTee34.Begin();
            MoveTee35.Begin();
            MoveTee36.Begin();
            MoveTee37.Begin();
            MoveTee38.Begin();
            MoveTee39.Begin();
            MoveTee40.Begin();
            MoveTee41.Begin();
            MoveTee42.Begin();
            MoveTee43.Begin();
            MoveTee44.Begin();
            MoveTee45.Begin();
            MoveTee46.Begin();
            MoveTee47.Begin();
            MoveTee48.Begin();
            MoveTee49.Begin();
        }

        // *************************************
        // * The PopulatePoints function generates
        // * the 50 coordinate locations for the 
        // * tee objects. 
        // *************************************
        private void PopulatePoints()
        {
            double XLocation = 0;
            double YLocation = 0;

            for (int i = 0; i < 50; i++)
            {
                Point Coordinate = new Point(XLocation, YLocation);
                TeeLocations.Add(Coordinate);
                XLocation += 95;

                // move to second row
                if (i == 9) { XLocation = 0; YLocation += 95; }

                // move to third row
                if (i == 19) { XLocation = 0; YLocation += 95; }

                // move to fourth row
                if (i == 29) { XLocation = 0; YLocation += 95; }

                // move to fifth row
                if (i == 39) { XLocation = 0; YLocation += 95; }
            }
        }

        // *************************************
        // * The ClearTextBold method clears the 
        // * bold style from the "year" text objects
        // * beneath the timeline, and also returns
        // * the font size to 10 (they are changed
        // * to 11 when selected).
        // *************************************
        private void ClearTextBold()
        {
            txt1987.FontWeight = FontWeights.Normal;
            txt1987.FontSize = 10;
            txt1988.FontWeight = FontWeights.Normal;
            txt1988.FontSize = 10;
            txt1989.FontWeight = FontWeights.Normal;
            txt1989.FontSize = 10;
            txt1990.FontWeight = FontWeights.Normal;
            txt1990.FontSize = 10;
            txt1991.FontWeight = FontWeights.Normal;
            txt1991.FontSize = 10;
            txt1992.FontWeight = FontWeights.Normal;
            txt1992.FontSize = 10;
            txt1993.FontWeight = FontWeights.Normal;
            txt1993.FontSize = 10;
            txt1994.FontWeight = FontWeights.Normal;
            txt1994.FontSize = 10;
            txt1995.FontWeight = FontWeights.Normal;
            txt1995.FontSize = 10;
            txt1996.FontWeight = FontWeights.Normal;
            txt1996.FontSize = 10;
            txt1997.FontWeight = FontWeights.Normal;
            txt1997.FontSize = 10;
            txt1998.FontWeight = FontWeights.Normal;
            txt1998.FontSize = 10;
            txt1999.FontWeight = FontWeights.Normal;
            txt1999.FontSize = 10;
            txt2000.FontWeight = FontWeights.Normal;
            txt2000.FontSize = 10;
            txt2001.FontWeight = FontWeights.Normal;
            txt2001.FontSize = 10;
            txt2002.FontWeight = FontWeights.Normal;
            txt2002.FontSize = 10;
            txt2003.FontWeight = FontWeights.Normal;
            txt2003.FontSize = 10;
            txt2004.FontWeight = FontWeights.Normal;
            txt2004.FontSize = 10;
            txt2005.FontWeight = FontWeights.Normal;
            txt2005.FontSize = 10;
            txt2006.FontWeight = FontWeights.Normal;
            txt2006.FontSize = 10;
            txt2007.FontWeight = FontWeights.Normal;
            txt2007.FontSize = 10;
        }

        /// <summary>
        /// StateLabels has specialized HTML for each state name
        /// </summary>
        private void InitializeStateLabels()
        {
            StateLabels.Add("AK", "<span class='state-abbr'>A</span>LAS<span class='state-abbr'>K</span>A");
            StateLabels.Add("AL", "<span class='state-abbr'>AL</span>ABAMA");
            StateLabels.Add("AR", "<span class='state-abbr'>AR</span>KANSAS");
            StateLabels.Add("AZ", "<span class='state-abbr'>A</span>RI<span class='state-abbr'>Z</span>ONA");
            StateLabels.Add("CA", "<span class='state-abbr'>CA</span>LIFORNIA");
            StateLabels.Add("CO", "<span class='state-abbr'>CO</span>LORADO");
            StateLabels.Add("CT", "<span class='state-abbr'>C</span>ONNECTICU<span class='state-abbr'>T</span>");
            StateLabels.Add("DE", "<span class='state-abbr'>DE</span>LAWARE");
            StateLabels.Add("FL", "<span class='state-abbr'>FL</span>ORIDA");
            StateLabels.Add("GA", "<span class='state-abbr'>G</span>EORGI<span class='state-abbr'>A</span>");
            StateLabels.Add("HI", "<span class='state-abbr'>H</span>AWAI<span class='state-abbr'>I</span>");
            StateLabels.Add("IA", "<span class='state-abbr'>I</span>OW<span class='state-abbr'>A</span>");
            StateLabels.Add("ID", "<span class='state-abbr'>ID</span>AHO");
            StateLabels.Add("IL", "<span class='state-abbr'>IL</span>LINOIS");
            StateLabels.Add("IN", "<span class='state-abbr'>IN</span>DIANA");
            StateLabels.Add("KS", "<span class='state-abbr'>K</span>ANSA<span class='state-abbr'>S</span>");
            StateLabels.Add("KY", "<span class='state-abbr'>K</span>ENTUCK<span class='state-abbr'>Y</span>");
            StateLabels.Add("LA", "<span class='state-abbr'>L</span>OUISIAN<span class='state-abbr'>A</span>");
            StateLabels.Add("MA", "<span class='state-abbr'>MA</span>SSACHUSETTS");
            StateLabels.Add("MD", "<span class='state-abbr'>M</span>ARYLAN<span class='state-abbr'>D</span>");
            StateLabels.Add("ME", "<span class='state-abbr'>M</span>AIN<span class='state-abbr'>E</span>");
            StateLabels.Add("MI", "<span class='state-abbr'>MI</span>CHIGAN");
            StateLabels.Add("MN", "<span class='state-abbr'>M</span>I<span class='state-abbr'>N</span>NESOTA");
            StateLabels.Add("MO", "<span class='state-abbr'>M</span>ISS<span class='state-abbr'>O</span>URI");
            StateLabels.Add("MS", "<span class='state-abbr'>M</span>I<span class='state-abbr'>S</span>SISSIPPI");
            StateLabels.Add("MT", "<span class='state-abbr'>M</span>ON<span class='state-abbr'>T</span>ANA");
            StateLabels.Add("NC", "<span class='state-abbr'>N</span>ORTH <span class='state-abbr'>C</span>AROLINA");
            StateLabels.Add("ND", "<span class='state-abbr'>N</span>ORTH <span class='state-abbr'>D</span>AKOTA");
            StateLabels.Add("NE", "<span class='state-abbr'>NE</span>BRASKA");
            StateLabels.Add("NH", "<span class='state-abbr'>N</span>EW <span class='state-abbr'>H</span>AMPSHIRE");
            StateLabels.Add("NJ", "<span class='state-abbr'>N</span>EW <span class='state-abbr'>J</span>ERSEY");
            StateLabels.Add("NM", "<span class='state-abbr'>N</span>EW <span class='state-abbr'>M</span>EXICO");
            StateLabels.Add("NV", "<span class='state-abbr'>N</span>E<span class='state-abbr'>V</span>ADA");
            StateLabels.Add("NY", "<span class='state-abbr'>N</span>EW <span class='state-abbr'>Y</span>ORK");
            StateLabels.Add("OH", "<span class='state-abbr'>OH</span>IO");
            StateLabels.Add("OK", "<span class='state-abbr'>OK</span>LAHOMA");
            StateLabels.Add("OR", "<span class='state-abbr'>OR</span>EGON");
            StateLabels.Add("PA", "<span class='state-abbr'>P</span>ENNSYLVANI<span class='state-abbr'>A</span>");
            StateLabels.Add("RI", "<span class='state-abbr'>R</span>HODE <span class='state-abbr'>I</span>LAND");
            StateLabels.Add("SC", "<span class='state-abbr'>S</span>OUTH <span class='state-abbr'>C</span>AROLINA");
            StateLabels.Add("SD", "<span class='state-abbr'>S</span>OUTH <span class='state-abbr'>D</span>AKOTA");
            StateLabels.Add("TN", "<span class='state-abbr'>T</span>E<span class='state-abbr'>N</span>NESSEE");
            StateLabels.Add("TX", "<span class='state-abbr'>T</span>E<span class='state-abbr'>X</span>AS");
            StateLabels.Add("UT", "<span class='state-abbr'>UT</span>AH");
            StateLabels.Add("VA", "<span class='state-abbr'>V</span>IRGIN<span class='state-abbr'>A</span>");
            StateLabels.Add("VT", "<span class='state-abbr'>V</span>ERMON<span class='state-abbr'>T</span>");
            StateLabels.Add("WA", "<span class='state-abbr'>WA</span>SHINGTON");
            StateLabels.Add("WI", "<span class='state-abbr'>WI</span>SCONSIN");
            StateLabels.Add("WV", "<span class='state-abbr'>W</span>EST <span class='state-abbr'>V</span>IRGINIA");
            StateLabels.Add("WY", "<span class='state-abbr'>WY</span>OMING");
        }

        /// <summary>
        /// Given a state, tells whether the state should be highlighted, based on which legend category is selected
        /// </summary>
        /// <param name="state">A State object</param>
        /// <returns>True if the state falls into the selected range on the legend; false otherwise</returns>
        private bool Highlighted(State state)
        {
            if (Category1Selected)
            {
                return (state.Obesity == 0);
            }
            else if (Category2Selected)
            {
                return (state.Obesity >= 1 && state.Obesity < 10);
            }
            else if (Category3Selected)
            {
                return (state.Obesity >= 10 && state.Obesity < 15);
            }
            else if (Category4Selected)
            {
                return (state.Obesity >= 15 && state.Obesity < 20);
            }
            else if (Category5Selected)
            {
                return (state.Obesity >= 20 && state.Obesity < 25);
            }
            else if (Category6Selected)
            {
                return (state.Obesity >= 25 && state.Obesity < 30);
            }
            else if (Category7Selected)
            {
                return (state.Obesity >= 30);
            }
            return false;

        }

        /// <summary>
        /// Takes a string which doesn't have a root element, and returns it as a list of XNodes
        /// </summary>
        /// <param name="xml">The XML fragment as a string</param>
        /// <returns>A list of XNodes</returns>
        private IEnumerable<XNode> ParseFragment(string xml)
        {
            string document = "<root>" + xml + "</root>";
            XElement root = XDocument.Parse(document).Element("root");

            return root.Nodes();
        }

        /// <summary>
        /// The HTML for a singe row of the standards-based bar chart
        /// </summary>
        /// <param name="state">The State for which to render the HTML</param>
        /// <returns>A list of XHTML elements</returns>
        private IEnumerable<XElement> StateRow(State state)
        {
            XElement root = new XElement("root");

            if (state.Obesity == 0)
                root.Add(
                    new XElement("span",
                        new XAttribute("class", "nodata"),
                        new XAttribute("style", "width: 77%"),
                        "No Data"
                    )
                );

            else
                root.Add(
                    new XElement("span",
                        new XAttribute("class", "obese"),
                        new XAttribute("style", "width: " + (state.Obesity * .75).ToString() + "%"),
                        state.Obesity.ToString() + "%"
                        ),
                    new XElement("span",
                        new XAttribute("class", "overweight"),
                        new XAttribute("style", "width: " + (state.Overweight * .75).ToString() + "%"),
                        state.Overweight.ToString() + "%"
                        ),
                    new XElement("span",
                        new XAttribute("class", "normal"),
                        new XAttribute("style", "width: " + ((100 - (state.Obesity + state.Overweight)) * .75).ToString() + "%"),
                        (100 - (state.Obesity + state.Overweight)).ToString() + "%"
                        )
                    );
            return root.Elements();
        }

        /// <summary>
        /// Get the full XHTML for the standards-based bar chart of all states data
        /// </summary>
        /// <param name="year">The year for which we are rendering an XHTML bar chart</param>
        /// <returns>An XHTML node containing the bar chart</returns>
        private XElement StatesTable(int year)
        {
            return
                new XElement("ul",
                    from state in Years[year]
                    orderby state.Abbr
                    select
                        new XElement("li",
                        new XElement("span",
                        new XAttribute("class", (Highlighted(state) ? "state selected" : "state")),
                        ParseFragment(StateLabels[state.Abbr])
                        ),
                        new XElement("span",
                        new XAttribute("class", "bar"),
                        StateRow(state)
                        )
                        )
               );

        }

    }
}
